package com.chendongyang.www.service;//进行用户账号的注册和登录;
import com.chendongyang.www.dao.lodgings;
import com.chendongyang.www.po.bileM;
import com.chendongyang.www.po.user;
import com.chendongyang.www.util.userId;
import java.sql.SQLException;
import java.util.Scanner;
public class longstanding {
           //进行账号的注册；
    String keHu;
    public int register() throws Exception {
        int line=0;
        String identity;
        System.out.println("请输入注册账号");
        Scanner input = new Scanner(System.in);
        String id = input.nextLine();
        System.out.println("请输入注册密码");
        String code = input.nextLine();
        System.out.println("您的真实姓名");
        String name=input.nextLine();
        System.out.println("请输入您的身份:1  校内人士 2 校外人士");
        int op=input.nextInt();
        if(op==1){
            identity="校内人士";
        }
        else  identity="校外人士";
        user user = new user(id, code);
        lodgings udi = new lodgings();
        boolean result = udi.select1(user.getId());
        if (result) {
            line = udi.insert(user,identity,name);
        } else {
            System.out.println("该用户已存在");
        }
        if (line == 1) {
            System.out.println("注册成功");
            System.out.println("=====================");
            keHu= user.getId();
            userId.Id=keHu;
            return 1;
        } else {
            System.out.println("注册失败");
            return 0;
        }
    }
    // 进行账号的登录；
    public int logIn() throws SQLException {
    //进行用户账号的登录
        System.out.println("请输入登录账号");
        Scanner input = new Scanner(System.in);
        String id = input.nextLine();
        System.out.println("请输入登录密码");
        String code = input.nextLine();
        user user=new user(id,code);
        lodgings udi=new lodgings();
        boolean result=udi.select(user);
        if(result){
            System.out.println("登录成功");
             keHu=id;
             userId.Id=keHu;
             return 1;
        }
        else{
            System.out.println("登录失败");
            return 0;
        }
    }

    public void improve() throws SQLException {
        //进行电动车信息的完善；
        Scanner input = new Scanner(System.in);
        System.out.println("==================");
        System.out.println("请输入车名");
        String bileName = input.nextLine();
        System.out.println("请输入车的年龄");
        int bileAge = input.nextInt();
        System.out.println("请输入车的品牌");
        String a=input.nextLine();
        String bileBrand=input.nextLine();
        bileM bileM=new bileM(bileName,bileAge,bileBrand);
        lodgings udi=new lodgings();
        int line = udi.bileInsert(bileM,keHu);
        if(line==1){
            System.out.println("完善成功");
            System.out.println("===================");
        }else{
            System.out.println("完善失败");
        }
    }
}